package com.example.springaop.proxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.invoke.MethodHandleInfo;
import java.lang.reflect.Method;

public class CGLibIntercepter implements MethodInterceptor {
    //代理对象
    private Object target;

    public CGLibIntercepter(Object target) {
        this.target = target;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        //代理增强内容
        System.out.println("我是中介 开始代理");
        //通过反射调用被代理类的方法
        Object retVal = methodProxy.invoke(target,objects);
        //代理增强内容
        System.out.println("我是中介 代理结束");
        return retVal;
    }
}
